////////////////////////////////////////////////////////////////////////////
//
// Aux class to parse a CString into a CString array
//
//
#pragma once

class CTokenizer
{
public:
	CTokenizer(CString strInput, CString strDelimiter = ",")
	{
		/* ctor
		strInput  CString to parse
		strDelimiter CString defining the
		delimiter to split the
		input string by.

		The class will take the input string and
		split it into a CStringArray
		*/

		int nFound = strInput.Find(strDelimiter);
		// Loop the input string while it contains any delimiter
		while(nFound != -1)
		{
			CString strLeft;
			strLeft = strInput.Left(nFound);
			strInput = strInput.Right(strInput.GetLength()-(nFound+1));
			m_stra.Add(strLeft);
			nFound = strInput.Find(strDelimiter);
		}

		// Add the last part of the string
		if(strInput.GetLength())
			m_stra.Add(strInput);
	}

	int GetSize()
	{
		// The function will return
		// the number of strings parsed
		return (int) m_stra.GetSize();
	}

	void GetAt(int nIndex, CString& str)
	{
		// The string will get the
		// string at index nIndex

		VERIFY(nIndex<m_stra.GetSize());
		str=m_stra.GetAt(nIndex);
	}

	void GetAt(int nIndex, int& var)
	{
		// The string will get the
		// string at index nIndex,
		// returning it as an int

		VERIFY(nIndex<m_stra.GetSize());
		var=atoi(m_stra.GetAt(nIndex));
	}

	void GetAt(int nIndex, WORD& var)
	{
		// The string will get the
		// string at index nIndex,
		// returning it as a WORD

		VERIFY(nIndex<m_stra.GetSize());
		var=(WORD)atoi(m_stra.GetAt(nIndex));
	}

	void GetAt(int nIndex, DWORD& var)
	{
		// The string will get the
		// string at index nIndex,
		// returning it as a DWORD

		VERIFY(nIndex<m_stra.GetSize());
		var=(DWORD)atoi(m_stra.GetAt(nIndex));
	}

private:
	// The result array
	CStringArray m_stra;
};